home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
Virtual User 1.0
/
Example Scripts
/
ResEditStressTest
/
ResEditTest.vu
< prev
Wrap
Text File
|
1991-01-25
|
17KB
|
458 lines
#
# File: ResEdit_test.vu
#
# Contains: A ResEdit test script that creates a window for each of the predefined resource types.
# If you have a file called "vu-wants-1-of-each" on the topmost volume, this script
# will delete it and recreate it. This name is kept in a string called Res_file_name
# and can be changed if desired.
#
# This script does quite a bit so it takes a while to execute. If you would rather
# have it create some number of resource type windows less than the total, modify the
# value of Number_Of_Resources_To_Make. The following statement will create the
# first 15 resource types:
# Number_Of_Resources_To_Make := 15;
# The variable Number_Of_Resources_To_Make is used to pass a second parameter to
# create_one_of_each_type() which indicates the number of resource types you'd
# like created.
#
# This script demonstrates how to use the scroll command to scroll through a
# scrolling list of items. Run it and watch what it does with scrolling.
#
# Libraries: "UtilityTasksLib.vu"
#
# Prerequisites:
# Be sure the UtilityTasksLib.vu library is available.
# The Finder must be the active app.(preferably the only app. running).
# If the target is running under a 6.0.x system, then:
# The ResEdit app must be in the root directory as the first file listed
# (view by name and rename to start its name with 'aa' for example).
# Either this window should be open and no other;
# or the volume icon selected and no windows open.
# If the target is running under a 7.0.x system, then:
# The ResEdit app must be the first occurance of ResEdit which Finder's
# Find command will select. This is best accomplished by putting it in the
# frontmost window and removing any other files with 'ResEdit' in it's name.
#
# Written by: Jay Jessen and Rick Violet
#
# Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
#
# Change History:
#
# 6/7/89 Jay Created from an old version (optimized scrolling actions)
# 1/2/91 Rick Updated Jay's version so that this script will run against both
# ResEdit v1.2 and ResEdit v2.1 (under system 6.0x and system 7.0).
# In the process defined some new tasks modified some old tasks and
# task names
# 1/4/91 naga Modified the header comments
# 1/9/91 Rick Moved some Tasks to "UtilityTasksLib.vu"
#
# To Do:
#
Libraries "UtilityTasksLib.vu";
(************************************************************************************
* Task set_screen_dependents()
************************************************************************************)
task set_screen_dependents() begin
# Where to drag resource windows to get them out of the way
global Wind_x := 250; # hardwired for now
global Wind_y := 20; # hardwired for now
end;
(************************************************************************************
* Task clear_file(file_to_clear,check_selection := true)
* clears a file from Volume window,
* if check_selection is false it'll clear the current selection ( For ResEdit 1.2 )
************************************************************************************)
Task clear_file(file_to_clear,check_selection := true) begin
global Volume_name;
if(not match[window t:Volume_name o:1]!) begin
select [window t:Volume_name]!;
end;
if(check_selection) begin
type k: { "v" };
found_it := false;
while not found_it begin
UseKeyboardEquivalent("o");
if(match[staticText t:/The file≈has no resource fork≈Do you wish≈it ∂?/
w:[window o:1 s:dialog]]!) begin
select [button t:'Cancel']!;
type k: { downarrowKey };
end;
else begin
if (((match[window o:1]!).title) = file_to_clear) begin
found_it := true;
close [window o:1]!;
end;
else begin
close [window o:1]!;
type k: { downarrowKey };
end;
end;
end;
end;
select [menuItem t:'Clear' m:'Edit']!;
if match[button t:'OK']! and match[button t:'Cancel']! select [button t:'OK'];
end;
(************************************************************************************
* Task create_resource_file(res_file_name)
* Creates a resource file of name res_file_name.
* Replaces any previously existing file of that name. ( For ResEdit 1.2 )
************************************************************************************)
task create_resource_file(res_file_name)
begin
global Volume_name;
if(not match[window t:Volume_name o:1]!) begin
select [window t:Volume_name]!;
end;
select [menuItem title:'New' m:'File']!;
type keystrokes: { res_file_name };
select [button title:'OK']!;
if(match[button t:'OK' w:[window o:1]]!) begin
select [button t:'OK']!;
select [button t:'Cancel']!;
clear_file(res_file_name);
select [menuItem title:'New' m:'File']!;
type keystrokes: { res_file_name };
select [button title:'OK']!;
end;
end;
(************************************************************************************
* Task create_resource_file_2(res_file_name)
* Creates a resource file of name res_file_name.
* Replaces any previously existing file of that name. ( For ResEdit 2.1 )
************************************************************************************)
task create_resource_file_2(res_file_name) begin
global Volume_name;
if( not match [ window ] )
select [menuItem title:/New≈/ m:'File']!;
else
if( match[ button t:"New" ]! and match [ button t:"Open" ]! )
select [ button t:"new" ];
type keystrokes: { res_file_name };
select [button title:'New']!;
wait(2);
if(match[button t:'Replace' w:[window o:1]]!)
select [button t:'Replace']!;
end;
(************************************************************************************
* Task set_scroll_bar_globals()
* set global values for scroll bar in "Select New Type" dialog ( For ResEdit 1.2 )
************************************************************************************)
Task set_scroll_bar_globals()
Begin
global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
global Previous_scroller_setting;
select [menuItem title:/New≈/ m:'File']!;
# get the "select new type" dialog's bounding rect and put it in wind_rect
match [window ord:1 rect:?wind_rect]!;
# get the scroll bar's current setting and rectangle (in local coords)
current_scroller := match [scrollBar window_owner:[window ord:1]
setting:?cntrl_value
rect:?scroller_rect]!;
# ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
Scrollbar_left := scroller_rect[1];
Scrollbar_top := scroller_rect[2];
Scrollbar_right := scroller_rect[3];
Scrollbar_bottom := scroller_rect[4];
if(cntrl_value[1] = cntrl_value[2]) begin
global Done_scrolling := true;
end;
else begin
Previous_scroller_setting := cntrl_value;
end;
end;
(************************************************************************************
* Task set_scroll_bar_globals_2()
* set global values for scroll bar in "Select New Type" dialog ( For ResEdit 2.1 )
************************************************************************************)
task set_scroll_bar_globals_2() begin
global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
global Previous_scroller_setting;
select [menuItem title:/Create New Resource/ m:'Resource']!;
# get the "select new type" dialog's bounding rect and put it in wind_rect
match [window ord:1 rect:?wind_rect]!;
# get the scroll bar's current setting and rectangle (in local coords)
current_scroller := match [scrollBar window_owner:[window ord:1]
setting:?cntrl_value
rect:?scroller_rect]!;
# ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
Scrollbar_left := scroller_rect[1];
Scrollbar_top := scroller_rect[2];
Scrollbar_right := scroller_rect[3];
Scrollbar_bottom := scroller_rect[4];
if(cntrl_value[1] = cntrl_value[2]) begin
global Done_scrolling := true;
end;
else begin
Previous_scroller_setting := cntrl_value;
end;
end;
(************************************************************************************
* Task position_res_type_window()
* Position the resource type window, away from the volume window ( For ResEdit 1.2 )
************************************************************************************)
task position_res_type_window() begin
drag [window ord:1] absolute:{ global Wind_x,global Wind_y };
Wind_x := Wind_x + 1;
Wind_y := Wind_y + 2;
end;
(************************************************************************************
* Task select_next_type()
* scrolls to the next resource type in the "Select New Type" dialog
************************************************************************************)
task select_next_type() begin
global Previous_scroller_setting,Clicks_for_current_value;
global Done_scrolling;
global List_item_height;
global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
global Non_top_item_selection;
scroll [scrollBar w:[window o:1]] absolute: Previous_scroller_setting;
if(Done_scrolling) begin # ~~ only need to select the remaining visible items (no more scrolling)
move absolute: { Scrollbar_left - 10,
Scrollbar_top + ((Non_top_item_selection - 1) * List_item_height) + 5 };
Non_top_item_selection := Non_top_item_selection + 1;
end;
else begin
move absolute: { Scrollbar_right - 5,Scrollbar_bottom - 5 };
click;
match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
if(cntrl_value[1] = Previous_scroller_setting[1]) begin # ~~~~~~~ scroll value hasn't changed
Clicks_for_current_value := Clicks_for_current_value + 1;
for i := 1 to Clicks_for_current_value click;
end;
else begin
Clicks_for_current_value := 0;
end;
move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
end;
click;# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make the new selection
if (not Done_scrolling) begin
match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
Previous_scroller_setting := cntrl_value;
if (cntrl_value[1] = cntrl_value[2]) begin
Done_scrolling := true;
List_item_height :=
(Scrollbar_bottom - Scrollbar_top) / 7;# ~~~~~~~~~~~~~~~ 7 is the number of visible types
Non_top_item_selection := 2;# ~~~~~~~~~~~~~~~~~~~~ now used to select remaining visible items
end;
end;
end;
(************************************************************************************
* Task check_for_alert_or_position_window()
* checks for an alert and if one isn't there positions the window,
* else it logs the alert and dismisses it
************************************************************************************)
task check_for_alert_or_position_window() begin
if(match[button w:[window ord:1 style:dialog] t:'OK']!) begin
text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
println "dismissing dialog that came up after resource type selection -- static text messages follow:";
for each m in text_messages println " ∂t",m.t;
select [button t:'OK'];
end;
else begin
position_res_type_window();
end;
end;
(************************************************************************************
* Task check_for_alert_or_position_window_2()
* checks for an alert and if one isn't there positions the window,
* else it logs the alert and dismisses it. There is an exception for FOND resource
* ( For ResEdit 2.1 )
************************************************************************************)
Task check_for_alert_or_position_window_2()
begin
if(match[ button w:[window o:1 s:dialog ] t:'OK' ]!)
if( match[ statictext t:/≈Adding a font≈/ ]! )
Type k:{returnKey,"Chicago",tabKey,"12",returnKey};
else
begin
text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
println "dismissing dialog that came up after resource type selection -- static text messages follow:";
for each m in text_messages println " ∂t",m.t;
select [button t:'OK'];
end;
if( match [window t:/≈ID =≈/]! )
if ( match [window o:1 c:true]! )
close [window o:1];
else if( match [menuItem title:'Close' m:'File' e:1 ]! )
select [menuItem title:'Close' m:'File']!;
if( match [window t:?tText ] and tText <> global Res_file_name )
position_res_type_window();
end;
(************************************************************************************
* Task create_one_of_each_type( some_of_each := 0)
* This task creates one of each resource type if some_of_each is zero.
* It will create the first ten resource types if some_of_each is 10. etc. ( ResEdit 1.2 )
************************************************************************************)
task create_one_of_each_type( some_of_each := 0) begin
global Scrollbar_left,Scrollbar_top;
global Res_file_name;
set_scroll_bar_globals();
move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
click;
select [button t:'OK']!;
check_for_alert_or_position_window();
creations_count := 1;
while ((global Non_top_item_selection <> 8) and
((not some_of_each) or (creations_count <> some_of_each))) begin
if(not match[window t:Res_file_name o:1]!) select [window t:Res_file_name]!;
select [menuItem title:'New' m:'File']!;
select_next_type();
creations_count := creations_count + 1;
select [button t:'OK']!;
check_for_alert_or_position_window();
end;
end;
(****************************************************************************************************
* Task create_one_of_each_type_2( some_of_each )
* This task creates one of each resource type if some_of_each is zero.
* It will create the first ten resource types if some_of_each is 10. etc.
****************************************************************************************************)
task create_one_of_each_type_2( some_of_each := 0) begin
global Scrollbar_left,Scrollbar_top;
global Res_file_name;
set_scroll_bar_globals_2();
move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
click;
select [button t:'OK']!;
check_for_alert_or_position_window_2();
creations_count := 1;
while ((global Non_top_item_selection <> 8) and
((not some_of_each) or (creations_count <> some_of_each))) begin
select [window t:global Res_file_name];
select [menuItem title:'Create New Resource' m:'Resource']!;
select_next_type();
creations_count := creations_count + 1;
select [button t:'OK']!;
check_for_alert_or_position_window_2();
end;
end;
##########################################################################################
### Execution Begins Here ###
##########################################################################################
match [target t:?TargetName];
global ResEdit2;
global Volume_name;
global System7 := RunningSystemSeven();
if System7 println TargetName," Running System 7";
else println TargetName," Not Running System 7";
if System7
LaunchOk := LaunchAppInSystem7("ResEdit");
else
LaunchOk := LaunchAppInSystem6("ResEdit");
if not LaunchOk
GracefulExit("ResEdit failed to launch");
wait(2);
if( match [menu t:"Resource" ] )
begin
ResEdit2 := true;
println TargetName," Running ResEdit2.1";
end;
else
begin
ResEdit2 := false;
println TargetName," Running ResEdit1.2";
end;
# when Non_top_item_selection = 7,
# all types have been created (7 is the number of visible items)
Non_top_item_selection := 0;
Done_scrolling := false;
Clicks_for_current_value := 0;
## Set these as you like
Number_Of_Resources_To_Make := 10; # Number of resource windows. pass zero for all
Res_file_name := "vu-wants-1-of-each"; # File name to use
##
set_screen_dependents();
if ResEdit2
begin
if( match[ window t:"" o:1]! and not match[ button ] ) # Splash Screen?
Select [ Window o:1 ];
create_resource_file_2(Res_file_name);
create_one_of_each_type_2( Number_Of_Resources_To_Make );
verif_string := "window titles follow for verification";
println "∂n",verif_string;
for i := 1 to card(verif_string) print "=";
println;
for each w in collect[window] println w.title; # ~~~~~~~~ to verify that all the windows were created
select [menuItem t:'quit'];
select [ button t:"No" ];
end;
else
begin
match[window o:1 t:?Volume_name]!;
create_resource_file(Res_file_name);
create_one_of_each_type( Number_Of_Resources_To_Make );
verif_string := "window titles follow for verification";
println "∂n",verif_string;
for i := 1 to card(verif_string) print "=";
println;
for each w in collect[window] println w.title; # ~~~~~~~~ to verify that all the windows were created
clear_file(Res_file_name,true);
select [menuItem t:'quit'];
end;